
package com.idea.rdftree;

import java.util.Enumeration;

import javax.swing.ImageIcon;
import javax.swing.tree.TreeNode;

import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Statement;
import com.idea.resources.tree.TreeIcons;

public class LiteralNode extends AbstractRdfTreeNode implements RdfTreeNode {
	private Literal literal;

	public LiteralNode(
		RdfNodeMap nodeMap,
		Statement parentStatement,
		Literal literal) {
		super(nodeMap, parentStatement);
		this.literal = literal;
	}

	public RDFNode getRdfNode() {
		return literal;
	}
	
	public void setRdfValue(String value){
		try{
		literal = getModel().createLiteral(value);
		}catch(Exception exception){
			exception.printStackTrace();
		}
	}

	public TreeNode getChildAt(int childIndex) {
		// System.out.println("no kids Literal");
		return null;
	}

	public int getChildCount() {
		return 0;
	}

	public TreeNode getParent() {
		//   return getNodeMap().getTreeNode(RdfUtils.getParent(getNodeMap().getModel(),
		//          literal));
		return getNodeMap().getTreeNode((RDFNode)getParentStatement());
	}

	public boolean isLeaf() {
		return true;
	}

	public String toString() {
		return literal.toString();
	}

	public ImageIcon getIcon() {
		return TreeIcons.literalIcon;
	}

	public int getNodeType() {
		return RdfTreeNode.LITERAL;
	}

	public void delete() {
		getNodeMap().removeLiteral(literal);

		//	getNodeMap().removeStatement(getParentStatement());
		//removeStatement(getParentStatement());
		//super.removeFromParent();
	}

	public void rename(String newName) {
	}

	public int getIndex(TreeNode node) {
		return 0;
	}

	public boolean getAllowsChildren() {
		return false;
	}

	public Enumeration children() {
		return null;
	}
}
